// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import './mock/mock.js'

Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(axios)

Vue.prototype.$http = axios

router.beforeEach((to, from, next) => {
  // console.log(to.matched)
  // next({path: '/miss'})
  if (to.matched.length === 0) {
    next('/miss')
  } else {
    let token = sessionStorage.getItem('token')
    // console.log(to)
    if (to.meta.requireAuth === true) {
      if (token == undefined || token === '' || token == null) {
        next('/login')
      } else {
        next()
      }
    } else {
      if (token == undefined || token === '' || token == null) {
        next()
      } else {
        // console.log(to)
        if (to.name === 'login') {
          next('/index')
        } else {
          next()
        }
      }
    }
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
